package com.chen.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chen.entity.AccountB;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

@Mapper
public interface AccountBMapper extends BaseMapper<AccountB> {

    @Update("update account_b set rmb = rmb - #{rmbAmount} ,rmb_frozen = rmb_frozen + #{rmbAmount} where user_id = #{userId} and rmb_frozen = 0\n")
    int frozenRmbAmount(@Param("userId") int userId, @Param("rmbAmount") BigDecimal rmbAmount);

    @Update("update account_b set rmb_frozen =rmb_frozen -  #{rmbAmount},dollar = dollar + #{rmbAmount} / 7 where user_id = #{userId} and rmb_frozen > 0")
    void commitRmbToRmb(@Param("userId") int userId, @Param("rmbAmount") BigDecimal rmbAmount);

    @Update("update account_b set rmb_frozen = rmb_frozen - #{rmbAmount},rmb = rmb + #{rmbAmount} where user_id = #{userId} and rmb_frozen > 0")
    void cancelRmbToRmb(@Param("userId") int userId, @Param("rmbAmount") BigDecimal rmbAmount);
}
